package com.insight.modules.system.job;

import lombok.extern.slf4j.Slf4j;
import com.insight.common.util.DateUtils;
import com.insight.common.util.MPRefreshTokenUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author JinPengDong
 * @date 2023/1/12
 */
@Slf4j
@Component
public class MPRefreshTokenJob implements Job {

    // 注入小程序刷新Token的工具类
    @Autowired
    private MPRefreshTokenUtil mpRefreshTokenUtil;

    /**
     * 定时任务执行入口方法
     * 每次任务触发时调用，负责刷新小程序的AccessToken
     *
     * @param context 任务执行上下文，包含任务详情信息
     * @throws JobExecutionException 任务执行异常时抛出
     */
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        log.info("Job Execution key：" + context.getJobDetail().getKey());
        log.info("定时刷新小程序token，时间：" + DateUtils.getTimestamp());
        // 调用工具类获取最新的AccessToken
        mpRefreshTokenUtil.getAccessToken();
    }
}

